import re

class MatchFinder(object):
    def __init__(self, classes):
        self.classes = classes

    def process(self, content):
        using_namespaces = re.findall('using\s+namespace\s+([^;]+)\s*;', content)
        ocurrences = dict()
        for klass in self.classes:
            r = self._find_ocurrences(content, klass)
            if '::' in klass:
                r += self._find_ocurrences(content, klass.split('::')[1])
            if r:
                ocurrences[klass] = set(r)
        return ocurrences

    def _find_ocurrences(self, content, klass):
        #TODO: nested <> and ->
        return ["%s< %s >" % (klass, p.strip(" ;")) for p in re.findall(klass + '<([\w\number]+)>', content)]

